//
//  HUDProgress.m
//  shaliangApp
//
//  Created by Adam Vijay on 2018/8/23.
//  Copyright © 2018年 Facebook. All rights reserved.
//

#import "HUDProgress.h"
#import "SVProgressHUD.h"
#import "UIColor+Hex.h"
#import <React/RCTConvert.h>

@implementation RCTConvert (SVProgressHUD)

RCT_ENUM_CONVERTER(SVProgressHUDStyle, (@{
                                          @"light" : @(SVProgressHUDStyleLight),
                                          @"dark" : @(SVProgressHUDStyleDark),
                                          @"custom" : @(SVProgressHUDStyleCustom)
                                          }), SVProgressHUDStyleLight, integerValue)

RCT_ENUM_CONVERTER(SVProgressHUDMaskType, (@{
                                          @"None" : @(SVProgressHUDMaskTypeNone),
                                          @"Clear" : @(SVProgressHUDMaskTypeClear),
                                          @"Black" : @(SVProgressHUDMaskTypeBlack),
                                          @"Gradient" : @(SVProgressHUDMaskTypeGradient),
                                          @"Custom" : @(SVProgressHUDMaskTypeCustom),
                                          }), SVProgressHUDMaskTypeNone, integerValue)



@end
@implementation HUDProgress
RCT_EXPORT_MODULE();

RCT_EXPORT_METHOD(showWithStatus:(NSString *)status)
{
  dispatch_async(dispatch_get_main_queue(), ^{
  [SVProgressHUD showWithStatus:status];
    });
}
RCT_EXPORT_METHOD(dismiss:(RCTResponseSenderBlock)block)
{
  dispatch_async(dispatch_get_main_queue(), ^{
    [SVProgressHUD dismissWithCompletion:^{
      block(@[[NSNull null]]);
    }];
  });
}
RCT_EXPORT_METHOD(showErrorWithStatus:(NSString *)status)
{
  dispatch_async(dispatch_get_main_queue(), ^{
  [SVProgressHUD showErrorWithStatus:status];
    });
}
RCT_EXPORT_METHOD(showSuccessWithStatus:(NSString *)status)
{
  dispatch_async(dispatch_get_main_queue(), ^{
  [SVProgressHUD showSuccessWithStatus:status];
    });
}
RCT_EXPORT_METHOD(setMinimumSize:(float)width :(float)height)
{
  dispatch_async(dispatch_get_main_queue(), ^{
  [SVProgressHUD setMinimumSize:CGSizeMake(width, height)];
       });
}
RCT_EXPORT_METHOD(setImageViewSize:(float)width :(float)height)
{
  dispatch_async(dispatch_get_main_queue(), ^{
  [SVProgressHUD setImageViewSize:CGSizeMake(width, height)];
          });
}

RCT_EXPORT_METHOD(setDefaultStyle:(NSString *) style)
{
  dispatch_async(dispatch_get_main_queue(), ^{
  [SVProgressHUD setDefaultStyle:[RCTConvert SVProgressHUDStyle:style]];
          });
}

RCT_EXPORT_METHOD(setDefaultMaskType:(NSString *) style)
{
  dispatch_async(dispatch_get_main_queue(), ^{
  [SVProgressHUD setDefaultMaskType:[RCTConvert SVProgressHUDMaskType:style]];
          });
}
RCT_EXPORT_METHOD(setBackgroundColor:(NSString *) color)
{
  dispatch_async(dispatch_get_main_queue(), ^{
  [SVProgressHUD setBackgroundColor:[UIColor colorWithHexString:color]];
          });
}
@end
